package com.bb.blog.security.common;

import com.bb.blog.web.component.ResponseUtil;
import com.bb.blog.web.model.CommonResponse;
import org.springframework.http.HttpStatus;
import org.springframework.security.access.AccessDeniedException;
import org.springframework.security.web.access.AccessDeniedHandler;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

public class CommonAccessDeniedHandler implements AccessDeniedHandler {
    @Override
    public void handle(HttpServletRequest request, HttpServletResponse response, AccessDeniedException accessDeniedException) throws IOException, ServletException {
        CommonResponse commonResponse = ResponseUtil.fail(HttpStatus.FORBIDDEN, "无权限访问");
        ResponseUtil.parseResponse(response, commonResponse);
    }
}
